package org.springblade.modules.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.modules.system.entity.DoctorCategory;
import org.springblade.modules.system.mapper.DoctorCategoryMapper;
import org.springblade.modules.system.service.DoctorCategoryService;
import org.springblade.modules.system.utils.BusinessException;
import org.springblade.modules.system.utils.PageBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DoctorCategoryServiceImpl extends ServiceImpl<DoctorCategoryMapper, DoctorCategory> implements DoctorCategoryService {

    @Autowired
    private DoctorCategoryMapper doctorCategoryMapper;

    public PageBounds<DoctorCategory> openDoctorCategoryTable(String name, int currentPage, int pageSize) throws Exception {
        try {
			final int totalSize = doctorCategoryMapper.countByExample(name);
			PageBounds<DoctorCategory> pageBounds = new PageBounds<DoctorCategory>(currentPage, totalSize, pageSize);
			List<DoctorCategory> list = doctorCategoryMapper.selectByLimitPage(name, pageBounds.getOffset(), pageBounds.getPageSize());
			pageBounds.setPageList(list);
			return pageBounds;
        } catch (Exception e) {
            throw new BusinessException("获取医生列表失败！", e.getMessage());
        }
    }

    public List<DoctorCategory> selectAllDoctorCategory() throws BusinessException {
        try {
            return doctorCategoryMapper.selectAllDoctorCategory();
        } catch (Exception e) {
            throw new BusinessException("查询失败！", e.getMessage());

        }
    }

    public void deleteDoctorCategoryByIds(List<Integer> ids) throws BusinessException {
        try {
			doctorCategoryMapper.deleteByPrimaryKey(ids);
        } catch (Exception e) {
            throw new BusinessException("删除失败！",e.getMessage());
        }
    }

    public int deleteDoctorCategoryById(Integer id){

        return doctorCategoryMapper.deleteDoctorCategoryById(id);
    }

    public int addDoctorCategory(DoctorCategory doctorCategory) throws BusinessException{
        try {
            return doctorCategoryMapper.addDoctorCategory(doctorCategory);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 1;
    }

    public int updateDoctorCategory(DoctorCategory doctorCategory) {
        return doctorCategoryMapper.updateDoctorCategory(doctorCategory);
    }

}
